package alicuu.util;

import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;

import java.net.InetAddress;
import java.net.UnknownHostException;


/**
 * Created by IntelliJ IDEA.
 * User: danny
 * Date: 17/03/02/
 * Time: 16:13
 */
public class ESClientFactory {
    private static ESClientFactory instance = new ESClientFactory();

    private ESClientFactory() {

    }

    public static ESClientFactory getInstance() {
        return instance;
    }

    public Client getClient() {
        Settings settings = Settings.settingsBuilder().put("cluster.name", "secsmarts")
                .put("client.transport.sniff", "true").put("client.transport.ping_timeout", "60s").build();

        Client client = null;
        try {
            client = TransportClient.builder().settings(settings).build().addTransportAddress(
                    new InetSocketTransportAddress(InetAddress.getByName("10.1.1.172"), 9300));
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return client;
    }
}
